package com.supreme.orderserver.controller;

import com.alibaba.fastjson.JSONObject;
import com.supreme.commonboot.utils.AjaxResp;
import com.supreme.commonentity.mysql.primary.MBTest;
import com.supreme.orderserver.service.remote.ExpressService;
import com.supreme.orderserver.service.remote.SimpleService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "feign")
public class FeignController {

    private final ExpressService expressService;
    private final SimpleService simpleService;

    @Autowired
    public FeignController(ExpressService expressService, SimpleService simpleService) {
        this.expressService = expressService;
        this.simpleService = simpleService;
    }

    @GetMapping(value = "searchExpressProduct")
    public JSONObject searchExpressProduct() {
        return this.expressService.searchProduct();
    }

    @GetMapping(value = "simpleSeataTest")
    public AjaxResp simpleSeataTest() {
        return this.simpleService.test();
    }

    @PostMapping(value = "createTest")
    public AjaxResp createTest(@RequestBody MBTest test) {
        return this.simpleService.testCreate(test);
    }

    @PostMapping(value = "createOrderStorage")
    @GlobalTransactional()
    public AjaxResp createOrderStorage(@RequestBody JSONObject postData) {
        /*Long userId = postData.getLong("userId");
        String orderCode = postData.getString("orderCode");
        Integer count = postData.getInteger("count");
        Integer money = postData.getInteger("money");

        MBOrder order = new MBOrder()
                .setUserId(userId)
                .setOrderCode(orderCode)
                .setOrderType(1)
                .setGoodsId(1L)
                .setUserId(1L);
        MBOrder order1 = this.cloudOrderService.createOrder(order);

        MBStorage storage = new MBStorage()
                .setGoodsId(1L)
                .setStockNum(count);
        MBStorage storage1 = this.simpleService.createStorage(storage);

        return new RespRet().append("order", order1).append("storage", storage1);*/
        return AjaxResp.instance();
    }
}
